# 数据库配置 - 修改这里的值即可
import pymysql
DB_HOST = 'localhost'
DB_NAME = 'smartplant'
DB_USER = 'root'
DB_PASSWORD = '123456'  # 修改为你的密码
DB_PORT = 3306

def get_db_connection():
    try:
        connection = pymysql.connect(
            host=DB_HOST,
            database=DB_NAME,
            user=DB_USER,
            password=DB_PASSWORD,
            port=DB_PORT,
            charset='utf8mb4',
            cursorclass=pymysql.cursors.DictCursor
        )
        return connection
    except Exception as e:
        print(f"数据库连接错误: {e}")
        return None
